c# remove from list in foreach

65

c# remove from list in foreach -

myList.RemoveAll(x => x.SomeProp == "SomeValue");

remove item from list in for loop c# -

var data=new List<string>(){"One","Two","Three"};
for(int i=data.Count - 1; i > -1; i--)
{
    if(data[i]=="One")
    {
        data.RemoveAt(i);
    }
}

c# best way to loop and remove -

for (int i = safePendingList.Count - 1; i >= 0; i--)
{
    // some code
    // safePendingList.RemoveAt(i);
}

Comments

Submit
0 Comments